package gui;


import interfaces.BankRegistry;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.*;

import testit.GUITest;

import banking.*;

public class GUInewGiroAccount extends JFrame {
	
	JTextField textfield_accountName;
	JTextField textfield_accountNumber;
	JTextField textfield_typ;
	JTextField textfield_language;
	JTextField textfield_country;
	JTextField textfield_output;
	
	JButton	buttonCreateDepositeAccount;
	
	JLabel label_accountNumber;
	JLabel label_accountName;
	JLabel label_typ;
	JLabel label_language;
	JLabel label_country;

	
	public GUInewGiroAccount() {

		this.getContentPane().setLayout(null);

		this.guiGiroWindow();

		this.addWindowListener(new WindowListener() {

			public void windowClosed(WindowEvent arg0) {
			}

			public void windowActivated(WindowEvent e) {
			}

			public void windowClosing(WindowEvent e) {
				
			}
			
			public void windowDeactivated(WindowEvent e) {
			}

			public void windowDeiconified(WindowEvent e) {
			}

			public void windowIconified(WindowEvent e) {
			}

			public void windowOpened(WindowEvent e) {
			}
		});

	}

	public void paintComponent(Graphics g) {
	    super.paintComponents(g);
	    g.drawString("Account Number", 10, 40);
	  }
	
	public void guiGiroWindow() 
	{

		// Instanzieren:
		textfield_accountNumber = new JTextField();
		textfield_accountName = new JTextField();
		textfield_typ = new JTextField();
		textfield_language = new JTextField();
		textfield_country = new JTextField();
		textfield_output = new JTextField();
		
		buttonCreateDepositeAccount = new JButton("Create Account");
		
		label_accountNumber = new JLabel("Account Number:");
		label_accountName = new JLabel("Account Name:");
		label_typ = new JLabel("Typ:");
		label_language = new JLabel("Language:");
		label_country = new JLabel("Country:");
		
		
		//Action Listener
		buttonCreateDepositeAccount.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				try {
					createDepositeAccount();
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}

		});
		
		// position
		textfield_accountNumber.setBounds(150,40,200,25);
		textfield_accountName.setBounds(150, 80, 200, 25);
		textfield_typ.setBounds(150, 120, 200, 25);
		textfield_language.setBounds(150, 160, 200, 25);
		textfield_country.setBounds(150, 200, 200, 25);
		
		buttonCreateDepositeAccount.setBounds(75, 240, 200, 30);
		
		label_accountNumber.setBounds(10, 40, 150, 25);
		label_accountName.setBounds(10, 80, 150, 25);
		label_typ.setBounds(10, 120, 150, 25);
		label_language.setBounds(10, 160, 150, 25);
		label_country.setBounds(10, 200, 150, 25);
		
		
		
		// add elements
		this.getContentPane().add(textfield_country);
		this.getContentPane().add(textfield_typ);
		this.getContentPane().add(textfield_accountName);
		this.getContentPane().add(textfield_accountNumber);
		this.getContentPane().add(textfield_country);
		this.getContentPane().add(textfield_language);
		
		this.getContentPane().add(buttonCreateDepositeAccount);
		
		this.getContentPane().add(label_accountNumber);
		this.getContentPane().add(label_accountName);
		this.getContentPane().add(label_typ);
		this.getContentPane().add(label_language);
		this.getContentPane().add(label_country);
		

		this.pack();
	}

	public void createDepositeAccount() throws Exception{
		
		int	accountNumber = Integer.parseInt(textfield_accountNumber.getText());
		String accountName = textfield_accountName.getText();
		int runtime = Integer.parseInt(textfield_typ.getText());
		String language = textfield_language.getText();
		String country = textfield_country.getText();
		
		BankImpl Sparkasse = BankRegistry.loockup("Sparkasse");
		Sparkasse.newGiroAccount(accountNumber, accountName, runtime, language, country);

	}

	
}